package com.xiaoyang.controller;

import com.alibaba.fastjson.JSONObject;
import com.xiaoyang.service.WxPushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author guoziyang
 * @create 2020/9/21 8:59 下午
 */
@RestController
@RequestMapping("/api")
public class CallBackController {

    @Value("${CALLBACK_URL}")
    private String CALLBACK_URL;

    @Autowired
    private WxPushService wxPushService;

    @PostMapping("/callback")
    public void callBack(@RequestBody JSONObject jsonObject) {

        JSONObject data = jsonObject.getJSONObject("data");
        String uid = data.getString("uid").split("_")[1];
        String url = CALLBACK_URL + "/#/api/login?uid=" + uid;
        String content = "\uD83D\uDC49<a href=\"" + url + "\">点击登录今日校园</a>\uD83D\uDC48";
        wxPushService.wxPush(content, "UID_" + uid);

    }

}
